//
//  ThemeLabel.m
//  Custom_Weibo
//
//  Created by LEO on 12/9/15.
//  Copyright © 2015 Leo_Lei. All rights reserved.
//

#import "ThemeLabel.h"

@implementation ThemeLabel

#pragma mark - INTIALIZATION_METHODS
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self getNotification];
    }
    return self;
}

- (void)awakeFromNib {
    [self getNotification];
}

#pragma mark - MONITOR_NOTIFICATION
- (void)getNotification {
    //  Monitoring the notification when theme changed
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(themeDidChange:)
                                                 name:kThemeNotification
                                               object:nil];
}

#pragma mark - WHEM_THEME_CHANGED
- (void)themeDidChange:(NSNotification *)notification {
    [self loadColor];
}

#pragma mark SET_COLOR
- (void)setColorName:(NSString *)colorName {
    //  Get the object and set the corresponding color for font
    if (_colorName != colorName) {
        _colorName = [colorName copy];
        [self loadColor];
    }
}

#pragma mark GET_COLOR
- (void)loadColor {
    UIColor *fontColor = [[ThemeManager defaultManager] getThemeColor:_colorName];
    self.textColor = fontColor;
}

#pragma mark - DEALLOC
- (void)dealloc {
    //  Remove observer
    [[NSNotificationCenter defaultCenter] removeObserver:kThemeNotification];
}
@end
